Add wp db status command for database health overview - #307
Open
swissspidy with Copilot wants to merge 16 commits into
Open
Add wp db status command for database health overview#307swissspidy with Copilot wants to merge 16 commits into
wp db status command for database health overview#307swissspidy with Copilot wants to merge 16 commits into
Conversation
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add wp db status command for database health overview
Add Feb 1, 2026
wp db status command for database health overview
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This comment was marked as resolved.
This comment was marked as resolved.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (6)
src/DB_Command.php:1481
- The database size query also ignores
$exit_code/$stderrfromself::run(). On mysql failures this can lead to$db_sizebeing reported as0 Binstead of returning an error.
list( $stdout, $stderr, $exit_code ) = self::run(
$command,
array_merge( [ 'execute' => $db_size_query ], $assoc_args ),
false
);
src/DB_Command.php:1516
- The table info query (engine/charset/collation) ignores failures from
self::run(). If mysql errors here, the code will parse an empty/invalid$stdoutand silently fall back toN/A, masking real connection/query issues.
list( $stdout, $stderr, $exit_code ) = self::run(
$command,
array_merge( [ 'execute' => $table_info_query ], $assoc_args ),
false
);
src/DB_Command.php:1544
get_defaults_flag_string()mutates$assoc_argsby unsetting thedefaultskey. Sincestatus()calls it once when building the mysql$commandand again here when building$check_command, a--defaultsinvocation will incorrectly end up running mysqlcheck with--no-defaults(the second call no longer sees thedefaultsflag). Store the defaults flag string once and reuse it for both commands (or avoid mutating$assoc_args).
$check_command = sprintf(
'/usr/bin/env %s%s %s',
Utils\get_sql_check_command(),
$this->get_defaults_flag_string( $assoc_args ),
'%s'
src/DB_Command.php:1469
- The first
self::run()call captures$exit_code/$stderrbut ignores them. If the mysql client fails (bad creds, missing client, connection error), the command will silently continue with$table_countset to 0, producing incorrect output.
list( $stdout, $stderr, $exit_code ) = self::run(
$command,
array_merge( [ 'execute' => $table_count_query ], $assoc_args ),
false
);
src/DB_Command.php:1416
- The docblock claims “If WordPress is installed, additional details are included”, but
status()always prints the same fixed set of fields and does not branch on installation state. This is misleading for users readingwp help db status.
* This command works even when WordPress is not fully installed,
* providing minimal information. If WordPress is installed, additional
* details are included.
src/DB_Command.php:1444
status()doesn't callmaybe_load_sqlite_dropin()or handle SQLite the way other db commands do (e.g.check()). As written, it will attempt to runmysql/mysqlcheckeven when SQLite is the active DB engine, which will fail or produce misleading output.
This issue also appears in the following locations of the same file:
- line 1465
- line 1477
- line 1512
- line 1540
public function status( $_, $assoc_args ) {
global $table_prefix;
// Get database name from constants (available after wp-config loads).
$db_name = DB_NAME;
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a new
wp db statuscommand that provides a consolidated view of database health and configuration information in a single command, eliminating the need to run multiple separate database commands (wp db size,wp db tables,wp db prefix,wp db check).Implementation
New
status()method inDB_Commandclass that works without loading WordPressself::run()method instead of$wpdbfor database informationinformation_schema.TABLESfor table count, size, engine, charset, and collation$table_prefixvariable (wp-config.php)mysqlcheckfor health status--dbuser,--dbpass, and--defaultsoptions for authenticationCommand registration in
composer.jsonComprehensive Behat test coverage with regex matching for dynamic values and credential option testing
Key Features
after_wp_config_loadlevel (class default), similar towp db query$wpdbobjectaddslashes()with LIKE pattern escaping for securityOutput Example
Notes
wp db size --human-readablebehaviorOriginal prompt
wp db statuscommand for quick database health overview #306✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.